<?php

namespace app\command;

use app\service\ChatWorkerService;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
use Workerman\Worker;

class ChatAll extends Command
{
    public function configure()
    {
        $this->setName('ChatAll')
            ->setDescription('linux运行所有聊天服务')
            ->addArgument('action', Argument::REQUIRED, '')//start|stop|restart|reload|status
            ->addArgument('type', Argument::OPTIONAL, '', 'd');//d|daemon 守护进程
    }

    public function execute(Input $input, Output $output)
    {
        bs_log('come', 'ChatAll', 'cmd.log');

        //$action = $input->getArgument('action');
        $type = $input->getArgument('type');
        // 标记是全局启动
        define('GLOBAL_START', 1);
        ChatWorkerService::Register();
        ChatWorkerService::BusinessWorker();
        ChatWorkerService::Gateway();
        //以守护模式启动
        //Worker::$daemonize  = true;
        if ($type == 'd' || $type == 'daemon') {
            Worker::$daemonize = true;
        }
        // 运行所有服务
        Worker::runAll();

    }

}
